import { MockMethod, MockConfig } from 'vite-plugin-mock';

export default [
  {
    url: '/api/userList',
    method: 'get',
    response: ({ query }) => {
      const page = Number.parseInt(query.page) || 1; // 获取请求参数中的页码，默认为1
      const pageSize = Number.parseInt(query.pageSize) || 10; // 获取请求参数中的每页数量，默认为10

      // 假设总共有30个用户
      const total = 41;
      const totalPages = Math.ceil(total / pageSize); // 计算总页数

      // 根据页码和每页数量计算起始索引和结束索引
      const startIndex = (page - 1) * pageSize;
      const endIndex = Math.min(startIndex + pageSize, total);

      // 生成模拟的用户列表数据
      const list = [];
      for (let i = startIndex; i < endIndex; i++) {
        list.push({
          id: i + 1,
          name: `User ${i + 1}`,
          sex: i % 2 == 0 ? 'male' : 'female',
        });
      }

      return {
        code: 200,
        data: {
          list,
          total,
          page,
          pageSize,
          totalPages,
        },
      };
    },
  },
] as MockMethod[];
